package Thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo17 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService service = Executors.newFixedThreadPool(4);
        for (int i = 0; i < 100; i++) {
            int id = 1;
            service.submit(() -> {
                Thread current = Thread.currentThread();
                System.out.println("hello thread " + id + "," + current.getName());
            });
        }
        //不要立即终止,等待任务执行一段时间
        Thread.sleep(2000);

        //终止线程池的线程
        service.shutdown();
        System.out.println("程序退出");
    }
}
